fix(decorators): check for own metadata in command/query handler #1181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When there is two commands/queries that one inherits from the other and both of them have registered handlers, then metadata for them is defined only for parent and not for child. This causes the same ID to be generated for both commands/queries, sometimes resulting in wrong handler picking up the message.
Take a look at this example:
Snippet of previous implementation:
Now following previous behavior
ParentCommandHandler
would define metadata forParentCommand
with new ID, Then when checking ChildCommand it would checkhasMetadata
which will check for metadata not only for given class, but all it's parents. That would result in leaving the same ID both forParentCommand
andChildCommand
. The same applies for queries.It would sometimes cause wrong handler to pick up wrong message.
Worth noting is that
event-handler.decorator
useshasOwnMetadata
making a distinction between parent and child.What is the new behavior?
Now only own metadata will be checked.
Does this PR introduce a breaking change?
Actually it's debatable. Behavior of command and query handlers will be changing, meaning it will not pickup wrong commands by mistake, but it was not intended, I assume.
Other information